﻿using System.Windows.Forms;

namespace ExcelFileQueryTool
{
    public partial class ucSheetHeader : UserControl
    {
        private string _titleInitVal;
        private string _personInitVal;
        private string _phoneInitVal;
        private string _addressInitVal;

        public bool HasChanged
        {
            get
            {
                return this.SheetTitle != this._titleInitVal
                    || this.ContactPerson != this._personInitVal
                    || this.Phone != this._phoneInitVal
                    || this.Address != this._addressInitVal;
            }
        }

        public string SheetName
        {
            get { return this.gboxSheetHeader.Text; }
        }

        public string SheetTitle
        {
            get { return AppConfig.ClientFileSheetTitleFormat + this.txtTitle.Text.Trim(); }
            set { this.txtTitle.Text = value; }
        }

        public string ContactPerson
        {
            get { return this.txtName.Text.Trim(); }
            set { this.txtName.Text = value; }
        }

        public string Phone
        {
            get { return this.txtPhone.Text.Trim(); }
            set { this.txtPhone.Text = value; }
        }

        public string Address
        {
            get { return this.txtAddress.Text.Trim(); }
            set { this.txtAddress.Text = value; }
        }

        public ucSheetHeader(string sheetName, string title, string person, string phone, string address)
        {
            InitializeComponent();

            // remove word title format string
            if (string.IsNullOrEmpty(title) == false)
                title = title.Substring(title.LastIndexOf('&') + 3);

            this.gboxSheetHeader.Text = sheetName;
            this.txtName.Text = person;
            this.txtPhone.Text = phone;
            this.txtAddress.Text = address;
            this.txtTitle.Text = title;            

            _titleInitVal = title;
            _personInitVal = person;
            _phoneInitVal = phone;
            _addressInitVal = address;
        }
    }
}
